/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2025-02-17 22:26:40
 * @LastEditTime: 2025-02-27 00:22:37
 * @FilePath: /monitor_belt/src/views/home/components/run_state/index.tsx
 */
import { remotePLCParam } from "@/api/plc";
import DictionaryLabel from "@/components/dictionary_label";
import { useStore } from "@/store/conveyor";
import { DetectEvent, DetectList, MotortList } from "@/utils/dictionary";
import { Flex } from "antd";
import { useEffect, useState } from "react";

const RunState = () => {
  const [runInfo, setRunInfo] = useState<any>({});
   const { conveyorList } = useStore();
  useEffect(() => {
    search();
  }, []);

  const search = async () => {
    try {
      let res = await remotePLCParam();
      setRunInfo({ ...res.data });
    } finally {
    }
  };
  return (
    <Flex>
      {conveyorList.map((item,index: number) => {
        return (
          <Flex
            vertical
            justify="space-around"
            style={{ padding: "20px", fontSize: "14px" }}
            key={index}
          >
            <h2 style={{fontSize:'18px'}}>{item.conveyor}</h2>
            <Flex>
              运行状态：
              {runInfo?.conveyor_state ? (
                <DictionaryLabel
                  list={[...MotortList]}
                  label={"label"}
                  isDot
                  value={runInfo?.conveyor_state}
                />
              ) : null}
            </Flex>
            <Flex>
              撕裂预警：
              {runInfo?.tear_alarm ? (
                <DictionaryLabel
                  list={[...DetectList]}
                  label={"label"}
                  isDot
                  value={DetectEvent[runInfo?.tear_alarm]}
                />
              ) : null}
            </Flex>
            <Flex>电机转速：{runInfo?.motor_speed}</Flex>
            <Flex>电机温度：{runInfo?.temp}</Flex>
          </Flex>
        );
      })}
    </Flex>
  );
};

export default RunState;
